package com.youlu.campus.web.item;

import com.youlu.campus.entity.VO.req.ActivityFeedQueryVO;
import com.youlu.campus.service.item.ItemInfoService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品管理器
 */
@RestController
public class ItemInfoController {
    @Autowired
    private ItemInfoService itemInfoService;

    /**
     * 收藏商品
     *
     * @param itemId
     * @return
     */
    @GetMapping("/mini-app/item/user/favorite")
    public QResult favorite(@RequestParam("itemId") String itemId) {
        return QResult.success(itemInfoService.likeItem(RequestContext.getAppId(),
                RequestContext.getCurPlatform(), RequestContext.getUserId(), itemId));
    }

    /**
     * 取消收藏商品
     *
     * @param itemId
     * @return
     */
    @GetMapping("/mini-app/item/user/unfavorite")
    public QResult unFavorite(@RequestParam("itemId") String itemId) {
        return QResult.success(itemInfoService.unLikeItem(RequestContext.getAppId(),
                RequestContext.getCurPlatform(), RequestContext.getUserId(), itemId));
    }

    /**
     * 用户是否收藏商品
     *
     * @param itemId
     * @return
     */
    @GetMapping("/mini-app/item/user/favorited")
    public QResult favorited(@RequestParam("itemId") String itemId) {
        return QResult.success(itemInfoService.likedItem(RequestContext.getAppId(),
                RequestContext.getCurPlatform(), RequestContext.getUserId(), itemId));
    }

    /**
     * 活动任务Feed 流
     *
     * @param
     * @return
     */
    @PostMapping("/mini-app/item/feed")
    public QResult getTaskFeeds(@RequestBody ActivityFeedQueryVO req) {
        req.setUserId(RequestContext.getUserId());
        return QResult.success(itemInfoService.getFeedInfo("item", 1));
    }
}
